home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 June / SGI Freeware 1998 June.iso / dist / fw_viewfax.idb / usr / freeware / src / viewfax-2.3 / faxexpand.h.z / faxexpand.h
C/C++ Source or Header  |  1997-09-09  |  5KB  |  147 lines

  1. /* Include file for fax routines
  2.    Copyright (C) 1990, 1995  Frank D. Cringle.
  3.  
  4. This file is part of viewfax - g3/g4 fax processing software.
  5.      
  6. viewfax is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2 of the License, or (at your
  9. option) any later version.
  10.      
  11. This program is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. General Public License for more details.
  15.      
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  19.  
  20. #include <limits.h>
  21.  
  22. #if ULONG_MAX == 4294967295UL
  23. typedef unsigned long t32bits;
  24. #elif UINT_MAX == 4294967295UL
  25. typedef unsigned int t32bits;
  26. #else
  27. #error need a 32-bit unsigned type
  28. /* if you see the above error, add an #elif case for your architecture
  29.    and tell fdc@cliwe.ping.de about it */
  30. #endif
  31.  
  32. #if USHRT_MAX == 65535
  33. typedef unsigned short t16bits;
  34. #elif UINT_MAX == 65535
  35. typedef unsigned int t16bits;
  36. #else
  37. #error need a 16-bit unsigned type
  38. /* if you see the above error, add an #elif case for your architecture
  39.    and tell fdc@cliwe.ping.de about it */
  40. #endif
  41. typedef t16bits pixnum;
  42.  
  43. struct pagenode;
  44.  
  45. /* drawfunc() points to a function which processes a line of the
  46.    expanded image described as a list of run lengths.
  47.    run is the base of an array of lengths, starting with a
  48.    (possibly empty) white run for line number linenum.
  49.    pn points to the page descriptor */
  50. typedef void (*drawfunc)(pixnum *run, int linenum, struct pagenode *pn);
  51.  
  52. struct strip {            /* tiff strip descriptor */
  53.     off_t offset;        /* offset in file */
  54.     off_t size;            /* size of this strip */
  55. };
  56.  
  57. struct pagenode {        /* compressed page descriptor */
  58.     struct pagenode *prev, *next; /* list links */
  59.     char *name;            /* basename of file */
  60.     char *pathname;        /* full name of file */
  61.     int    nstrips;        /* number of strips */
  62.     int rowsperstrip;        /* number of rows per strip */
  63.     int stripnum;        /* current strip while expanding */
  64.     struct strip *strips;    /* array of strips containing fax data in file */
  65.     t16bits *data;        /* in-memory copy of strip */
  66.     size_t length;        /* length of data */
  67.     pixnum width;        /* width of page in pixels */
  68.     pixnum height;        /* height of page in lines */
  69.     int inverse;        /* black <=> white */
  70.     int lsbfirst;        /* bit order is lsb first */
  71.     int orient;            /* orientation - upsidedown, landscape, mirrored */
  72.     int vres;            /* vertical resolution: 1 = fine  */
  73.     void (*expander)(struct pagenode *, drawfunc);
  74.     void *extra;        /* used for Ximage */
  75. };
  76. extern struct pagenode *firstpage, *lastpage, *thispage;
  77. extern struct pagenode defaultpage;
  78.  
  79. /* page orientation flags */
  80. #define TURN_U    1
  81. #define TURN_L    2
  82. #define TURN_M    4
  83.  
  84. extern char *ProgName;
  85.  
  86. /* fsm state codes */
  87. #define S_Null        0
  88. #define S_Pass        1
  89. #define S_Horiz        2
  90. #define S_V0        3
  91. #define S_VR        4
  92. #define S_VL        5
  93. #define S_Ext        6
  94. #define S_TermW        7
  95. #define S_TermB        8
  96. #define S_MakeUpW    9
  97. #define S_MakeUpB    10
  98. #define S_MakeUp    11
  99. #define S_EOL        12
  100.  
  101. /* state table entry */
  102. struct tabent {
  103.     unsigned char State;
  104.     unsigned char Width;    /* width of code in bits */
  105.     pixnum Param;        /* run length */
  106. };
  107.  
  108. extern struct tabent MainTable[];     /* 2-D state table */
  109. extern struct tabent WhiteTable[];    /* White run lengths */
  110. extern struct tabent BlackTable[];    /* Black run lengths */
  111.  
  112. extern int verbose;
  113.  
  114. void MHexpand(struct pagenode *pn, drawfunc df);
  115. void g31expand(struct pagenode *pn, drawfunc df);
  116. void g32expand(struct pagenode *pn, drawfunc df);
  117. void g4expand(struct pagenode *pn, drawfunc df);
  118.  
  119. unsigned char * getstrip(struct pagenode *pn, int strip);
  120. struct pagenode *notefile(char *name);
  121. int notetiff(char *name);
  122.  
  123. /* initialise code tables */
  124. extern void faxinit(void);
  125. /* count lines in image */
  126. extern int G3count(struct pagenode *pn, int twoD);
  127.  
  128. /* get memory or abort if none available */
  129. extern char *xmalloc(unsigned int size);
  130.  
  131. #ifdef linux
  132. #define _HAVE_USLEEP
  133. #endif
  134.  
  135. #if defined(BSD) || defined(__FreeBSD__) || defined(_BSD_SOURCE)
  136. #define _HAVE_USLEEP
  137. #ifndef rindex
  138. #define rindex strrchr
  139. #endif
  140. #ifndef bcmp
  141. #define memcmp bcmp
  142. #endif
  143. #define memclr(p,n)    bzero(p,n)
  144. #else  /* not BSD */
  145. #define memclr(p,n)    memset(p,0,n)
  146. #endif
  147.